/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { LogCombineType } from '../../utils/log/log-combine-type.js';
import { ProcessUtils } from '../../utils/process-utils.js';

type CommandInput = {
  moduleName?: string;
  taskName?: string;
  commandLine: string[];
  integratedHspCommand: string[] | undefined;
  commandOptions?: object;
  logCompileType?: LogCombineType;
  logLevel?: string;
};

export async function warmUp() {
  // do nothing
}

export async function generalExecute(workData: CommandInput) {
  const { moduleName, taskName, commandLine, commandOptions, logCompileType, logLevel, integratedHspCommand } = workData;
  const processUtils = new ProcessUtils(moduleName, taskName, logLevel);
  await processUtils.execute(commandLine, commandOptions, logCompileType);
  if (integratedHspCommand) {
    await processUtils.execute(integratedHspCommand);
  }
}

export async function packageHar(workData: CommandInput) {
  const { moduleName, taskName, commandLine, commandOptions, logLevel } = workData;
  const result = await new ProcessUtils(moduleName, taskName, logLevel).execute(commandLine, commandOptions, LogCombineType.DEBUG);
  return result.stdout.toString();
}
